import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';
import { NotificationProvider } from '../../../providers/notification/notification';
import { ApiProvider } from '../../../providers/api/api';

/**
 * Generated class for the StoreFilterPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-store-filter',
  templateUrl: 'store-filter.html',
})
export class StoreFilterPage {
  private size: string;
  private code: string;
  private houseId:string;
  private houses:any;

  constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl: ViewController,public notification: NotificationProvider,public api: ApiProvider) {
  }
 
  ionViewDidLoad() {
    let res = this.api.getList('sp_house',{where_sql:'sp_house.house_level=1',where_type:'',where_value:''}).subscribe(res => {
      if(res['success']){
        this.houses = res['data']['root'];
      }else{
        this.notification.showAlert(res['message']); 
      } 
      this.notification.hideLoading(); 
    })
  }


  dismiss() {
    this.code = this.code || '';
    this.size = this.size || '';
    this.houseId = this.houseId || '';
    let data = {
      where_sql:'sp_store.sp_code like ? and sp_store.sp_type like ? and sp_store.house_id like ?',
      where_type:'string;string;string',
      where_value:'%'+this.code+'%;%'+this.size+'%;%'+this.houseId
    };
    this.viewCtrl.dismiss(data);
  }
}
